home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / computerjanitor / plugins / fstab_plugin.py < prev    next >
Encoding:
Python Source  |  2009-04-17  |  3.6 KB  |  124 lines

  1. # fstab_plugin.py - modify /etc/fstab to be similar to fresh install
  2. # Copyright (C) 2008  Canonical, Ltd.
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, version 3 of the License.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15.  
  16.  
  17. import fstab
  18.  
  19. import computerjanitor
  20. import computerjanitorapp
  21. _ = computerjanitorapp.setup_gettext()
  22.  
  23.  
  24. class FstabCruftBase(computerjanitor.Cruft):
  25.  
  26.     """Base class for cruft in the fstab file."""
  27.  
  28.     def __init__(self, fstab_line):
  29.         self.fstab_line = fstab_line
  30.  
  31.  
  32. class RelatimeCruft(FstabCruftBase):
  33.  
  34.     """Cruft consisting of a missing 'relatime' option for a filesystem."""
  35.         
  36.     def get_prefix(self):
  37.         return "relatime"
  38.         
  39.     def get_prefix_description(self):
  40.         return "fstab mount option relatime missing"
  41.         
  42.     def get_shortname(self):
  43.         return self.fstab_line.directory
  44.         
  45.     def get_description(self):
  46.         return _("The 'relatime' mount option is missing for filesystem "
  47.                 "mounted at %s") % self.fstab_line.directory
  48.                 
  49.     def cleanup(self):
  50.         if "relatime" not in self.fstab_line.options:
  51.             self.fstab_line.options += ["relatime"]
  52.  
  53.  
  54.  
  55. # FIXME: this should either be like the
  56. #    def _rewriteFstab(self) in DistUpgradeQuirks()
  57. # or not exit at all
  58. class Scd0Cruft(FstabCruftBase):
  59.  
  60.     """Rewrite iso9660 fs devices as/dev/cdrom in fstab."""
  61.  
  62.     def get_prefix(self):
  63.         return "scd0"
  64.         
  65.     def get_prefix_description(self):
  66.         return "/dev/scd0 should be /dev/cdrom"
  67.         
  68.     def get_shortname(self):
  69.         return "/dev/scd0"
  70.         
  71.     def get_description(self):
  72.         return _("The '/dev/scd0' device should be '/dev/cdrom' in fstab.")
  73.                 
  74.     def cleanup(self):
  75.         if self.fstab_line.device == "/dev/scd0":
  76.             self.fstab_line.device = "/dev/cdrom"
  77.  
  78.  
  79. class FstabPlugin(computerjanitor.Plugin):
  80.  
  81.     """Plugin to modify /etc/fstab.
  82.     
  83.     This plugin will add the relatime mount option to /etc/fstab
  84.     to those ext2 and ext3 filesystems that are missing it.
  85.     
  86.     In the future, it may do other things. We'll see. The goal is
  87.     to provide a way to add tweaks to /etc/fstab upon upgraded that
  88.     would be there if the system was installed from scratch.
  89.     
  90.     """
  91.     
  92.     allowed_fstypes = ["ext2", "ext3"]
  93.     
  94.     def __init__(self):
  95.         self.fstab_filename = "/etc/fstab"
  96.         self.fstab = None
  97.         
  98.     def is_relatime_cruft(self, line):
  99.         return (line.fstype in self.allowed_fstypes and
  100.                 "relatime" not in line.options and
  101.                 "noatime" not in line.options)
  102.  
  103.     def is_scd0_cruft(self, line):
  104.         # FIXME: deactivated for now, see above reason why
  105.         return False
  106.         #return line.device == "/dev/sc0"
  107.  
  108.     def get_cruft(self):
  109.         tests = [(self.is_relatime_cruft, RelatimeCruft),
  110.                  (self.is_scd0_cruft, Scd0Cruft)]
  111.  
  112.         self.fstab = fstab.Fstab()
  113.         self.fstab.read(self.fstab_filename)
  114.  
  115.         cruft = []
  116.         for line in self.fstab.lines:
  117.             for test, klass in tests:
  118.                 if test(line):
  119.                     cruft.append(klass(line))
  120.         return cruft
  121.  
  122.     def post_cleanup(self):
  123.         self.fstab.write(self.fstab_filename)
  124.